package cn.xspace.library.util;

/**
 * Created by liuchen on 2016/10/17.
 */

import com.ctnq.util.EncryptUtil;
import com.google.gson.Gson;
import com.xspace.android.xafcommon.appliction.BaseApplication;
import com.xspace.android.xafcommon.util.DateUtils;
import com.xspace.android.xafcommon.util.LogUtil;

import java.io.Serializable;
import java.util.Map;



/**
 * Created by wangtao on 2016/7/7.
 */
public class EncryptBean implements Serializable {
    private static final String TAG = "EncryptBean";
    private String sign_data;
    private String pro_data;
    private String app_type;
    private String app_platcode;
    private String app_version;
    //    private String user_id;
    private String time_stmap;

    public EncryptBean() {
    }

    /**
     * 构建请求加密
     *
     * @param
     */
    public EncryptBean(Map<String, Object> params) {
//        this.app_platcode = PreferencesUtils.getString(context, MyInfoUtil.getPlatCode(), "0");
        this.app_platcode = MyInfoUtil.getPlatCode();
//        this.app_type = "0";
        this.app_type = "0";
//        this.app_version = PackageUtils.getAppVersionName(context);
        this.app_version = MyInfoUtil.getAppId(BaseApplication.mInstance);


        this.pro_data = new Gson().toJson(params);
        LogUtil.v(TAG, "pro_data>>" + pro_data);
        this.time_stmap = DateUtils.getNowDateTime();
        this.sign_data = EncryptUtil.getInstance().getSignData(EncryptUtil.getInstance().parseJSON2Str(this.pro_data));/*签名*/
        LogUtil.v(TAG, "sign_data>>" + sign_data);
//        this.user_id = PreferencesUtils.getString(context, MyInfoUtil.getMyUserid(context), "");
//        this.user_id = TempEntity.USER_ID;
    }

    public EncryptBean(String jsonStr) {
        this.app_platcode = MyInfoUtil.getPlatCode();
        this.app_type = "0";
        this.app_version = MyInfoUtil.getAppId(BaseApplication.mInstance);
        this.pro_data = jsonStr;
        LogUtil.v(TAG, "pro_data>>" + pro_data);
        this.time_stmap = DateUtils.getNowDateTime();
        this.sign_data = EncryptUtil.getInstance().getSignData(EncryptUtil.getInstance().parseJSON2Str(this.pro_data));/*签名*/
        LogUtil.v(TAG, "sign_data>>" + sign_data);
    }

    /**
     * 获取加密最终发送数据
     *
     * @param encryptBean
     * @return
     */
    public String sendData(EncryptBean encryptBean) {
        return EncryptUtil.getInstance().getEncryptData(new Gson().toJson(encryptBean));
    }

    public String getApp_platcode() {
        return app_platcode;
    }

    public void setApp_platcode(String app_platcode) {
        this.app_platcode = app_platcode;
    }

    public String getApp_type() {
        return app_type;
    }

    public void setApp_type(String app_type) {
        this.app_type = app_type;
    }

    public String getApp_version() {
        return app_version;
    }

    public void setApp_version(String app_version) {
        this.app_version = app_version;
    }

    public String getPro_data() {
        return pro_data;
    }

    public void setPro_data(String pro_data) {
        this.pro_data = pro_data;
    }

    public String getReq_time() {
        return time_stmap;
    }

    public void setReq_time(String req_time) {
        this.time_stmap = req_time;
    }

    public String getSign_data() {
        return sign_data;
    }

    public void setSign_data(String sign_data) {
        this.sign_data = sign_data;
    }

//    public String getUser_id() {
//        return user_id;
//    }
//
//    public void setUser_id(String user_id) {
//        this.user_id = user_id;
//    }
}
